<template>
  <div class="flex h-full">
    <a-card class="mr-2 w-64" :body-style="{ height: '97%', display: 'flex', flexDirection: 'column', padding: '8px' }">
      <template #title>
        <BaseTitle title="客户标签类别" class="mt-2" />
      </template>
      <LabelCategory ref="LabelCategoryRef" @select="onChangeLabel" />
    </a-card>
    <a-card class="flex-1 min-w-0">
      <template #title>
        <div class="flex justify-between mt-2">
          <BaseTitle title="客户标签" />
        </div>
      </template>
      <BaseTable :loading="loadingTable" :data-source="tableData" fill :columns="columns" :scroll="{ x: 1100 }" @change="onPageChange">
        <template #bodyCell="{ column, index }">
          <template v-if="column.dataIndex === 'xh'">
            {{ index + 1 }}
          </template>
        </template>
        <!-- {{ store.currentRole }} -->
      </BaseTable>
    </a-card>
  </div>
</template>

<script setup>
import { ref, watch } from 'vue'
import BaseTable from '@/components/BaseTable'
import { post } from '@/utils/request'
import LabelCategory from './components/LabelCategory'

const labelObject = ref({})
const LabelCategoryRef = ref()
const loadingTable = ref(false)
const tableData = ref([])
const columns = ref([
  {
    title: '序号',
    dataIndex: 'xh',
    width: 60
  },
  {
    title: '客户标签',
    dataIndex: 'itemName'
  },
  {
    title: '等级',
    dataIndex: 'itemLevel'
  },
  {
    title: '顺序号',
    dataIndex: 'outOrder'
  }
])
const onChangeLabel = (e) => {
  labelObject.value = e
}
//获取数据
const getData = async () => {
  loadingTable.value = true
  const { data, code } = await post('/operation/opex/getDictLabelItemList', { labelId: labelObject.value.id })
  loadingTable.value = false
  if (code !== 0) return
  tableData.value = data
}

watch(
  () => labelObject.value.id,
  (val) => {
    val && getData()
  }
)
</script>
<style lang="less" scoped>
:deep(.ant-radio-button-wrapper) {
  padding: 0 25px;
}
</style>
